import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:safetymonitor/app/components/common/no_permissions_widget.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_title_chart_page.dart';
import 'package:safetymonitor/app/components/custom_refresh.dart';
import 'package:safetymonitor/app/core/core.dart';
import 'package:safetymonitor/app/core/ext/ext.dart';
import 'package:safetymonitor/app/data/entities/home/enterprise/enterprise_staff_entity_entity.dart';
import 'package:safetymonitor/modules/home/enterprise/people_or_papers/details.dart';

import 'people_or_papers_controller.dart';

///人员及证件照
class PeopleOrPapersPage extends StatelessWidget {
  PeopleOrPapersPage({super.key});

  final controller = Get.put(PeopleOrPapersController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: controller,
      builder: (_) {
        if (!controller.isNotPermissions) {
          return const NoPermissionsWidget(boolTOP:false);
        }
        return Scaffold(
          body: Container(
            color: const Color(0xFFF7FBFE),
            padding: EdgeInsets.symmetric(vertical: 12.w, horizontal: 14.w),
            child: Column(
              children: [
                Expanded(
                  child: CustomEasyRefreshList<EnterpriseStaffEntityEntity>(
                    key: controller.globalKey,
                    dataLoad: controller.enterpriseStaffPage,
                    enableLoad: false,
                    itemBuilder: (item, index) {
                      return CustomTitleChartPage(
                        title: item.companyName,
                        titleRightWidget: const Icon(Icons.keyboard_arrow_right,),
                        child: itemWeight(item),
                      ).clickOnce(() {
                        Get.to(PeopleDetails.new,arguments: item);
                      });
                    },
                  ),
                )
              ],
            ),
          ),
        );
      },
    );
  }

  Widget _title(String title, String? value) {
    return Row(
      children: [
        Text(
          '$title：',
          style: TextStyle(
            fontSize: 14.sp,
            fontWeight: FontWeight.w400,
            color: const Color(0xFFC7CEE5),
          ),
        ),
        Expanded(
          child: Align(
            alignment: Alignment.centerLeft,
            child: Text(
              value ?? '空',
              style: TextStyle(
                fontSize: 14.sp,
                fontWeight: FontWeight.w400,
                color: const Color(0xFF1D3452),
              ),
            ),
          ),
        ),
      ],
    );
  }
  Widget itemWeight(EnterpriseStaffEntityEntity item) {
    //对象
    return Column(
      children: [
        Row(
          children: [
            Expanded(child: _title('部门', item.deptName??'')),
            Expanded(child: _title('班组', item.teamName??'')),
          ],
        ),
        AppGaps.vGap8,
        Row(
          children: [
            Expanded(child: _title('姓名', item.staffName??'')),
            Expanded(child: _title('员工编号', item.archiveNumber??'')),
          ],
        ),
        AppGaps.vGap8,
        Row(
          children: [
            Expanded(child: _title('性别', item.sex==1?'男':'女')),
            Expanded(child: _title('岗位（工种）',item.jobName??'')),
          ],
        ),
      ],
    );
  }
}
